#pragma once
#include <osg/ref_ptr>
#include <osgGA/GUIEventHandler>
#include <osgEarthFeatures/FeatureModelGraph>
#include <osgEarthFeatures/FeatureListSource>
#include <osgEarthAnnotation/FeatureEditing>
 
class GlobelSetting
{
public:

	static  GlobelSetting  *instance ;

	static GlobelSetting  * GetInstance()
	{
		if( instance == NULL)
		{
			instance  = new GlobelSetting();
		}
		return  instance;

	}
	void Release()
	{
		if(instance)
		{
			delete  instance;
		}
		instance  =0;
	}
 
	void SetGlobelEventHandler(osgGA::GUIEventHandler *  handler)
	{
		GlobelEventHandler  = handler;
	}
	osgEarth::Features::FeatureModelGraph  *GetGlobelFeatureModelGraph()
	{

		return  _features.get();
	}
	void SetPickedNode(osg::Node *node)
	{
      if(pickNode.get()  != node)
	  {
		  	pickNode = node;
	  }
	
	}
	void SetGlobelFeatureModelGraph(osgEarth::Features::FeatureModelGraph  * value)
	{
		_features =  value;
	}
	osgEarth::Features::FeatureListSource   * GetGlobelFeatureListSource()
	{
		if(!s_source.valid())
		{
			s_source = new  osgEarth::Features::FeatureListSource();
		}
		return  s_source.get();
	}
	void SetGlobelFeatureListSource ( osgEarth::Features::FeatureListSource * value)
	{
		s_source = value;

	}
	osgEarth::Symbology::Geometry * GetGlobelGeometry()
	{
		return  geometry.get();
	}
	void SetGlobelGeometry(osgEarth::Symbology::Geometry *value)
	{
		geometry = value;
	}
	void  SetGlobelAddPointHandler(osgEarth::Annotation::AddPointHandler *handler)
	{

		s_addPointHandler = handler;
	}
	osgEarth::Annotation::AddPointHandler * GetGlobelAddPointHandler()
	{
		if(!s_addPointHandler.valid())
		{
			osg::ref_ptr<osgEarth::Annotation::AddPointHandler> handler = new osgEarth::Annotation::AddPointHandler(active_feature.get(),GlobelSetting::GetInstance()->GetGlobelFeatureListSource(), mapnode.get()->getMap()->getProfile()->getSRS());
			handler.get()->setIntersectionMask( 0x1 );
			s_addPointHandler = handler.get();
		}
		return  s_addPointHandler.get();
	}
	void SetMapNode(osgEarth::MapNode  * node)
	{
		mapnode  = node;
	}
	void SetActiveFeature(osgEarth::Features::Feature * value)
	{
		active_feature = value;
	}
protected:
	GlobelSetting(void);


private:
	osg::ref_ptr<osg::Node>  pickNode;
	osg::ref_ptr<  osgEarth::Features::FeatureModelGraph > _features;
	osg::ref_ptr<osgGA::GUIEventHandler>  GlobelEventHandler;
	osg::ref_ptr< osgEarth::Features::FeatureListSource > s_source;
	osg::ref_ptr<osgEarth::Symbology::Geometry > geometry;
	osg::ref_ptr<osgEarth::Annotation::AddPointHandler> s_addPointHandler ;
	osg::ref_ptr<osgEarth::MapNode>  mapnode  ;
	osg::ref_ptr<osgEarth::Features::Feature >  active_feature;
};
